﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using LdtDataEngin.ModuleDetail.BaseModule.Optimization;
using LdtDataEngin.ModuleDetail.OptimizationModule;
using LdtJudge.DataEngine.Common;
using LdtJudge.DataEngine.Common.XmlUtility;
using LdtJudge.DataEngine.Data.DataParseStorage;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.XMLConfigModel.DataStores;
using LdtJudge.DataEngine.Model.XMLConfigModel.EvidenceElementConfigModel;
using Newtonsoft.Json;

namespace LdtDataEngin.ModuleDetail.CommonModule.EvidenceElementOptimize
{
    /// <summary>
    /// 证据要素优选
    /// </summary>
    public class EvidenceElementOptimizeDetail:OptimizationBase
    {
        //证据定位配置
        public EvidenceLocationConfig evidenceLocationConfig = new EvidenceLocationConfig();
        //阶段定位配置
        public StageConfig stageConfig = new StageConfig();

        public EvidenceElementOptimizeDetail(DataContext dataContext ,string moduleName)
        {
            this.dataContext = dataContext;
            this.ModuleName = moduleName;
            var configModel = dataContext.DataLayerSys.GetConfigModel(moduleName);
            string optimizeContent = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower() == "evidenceoptimize")?.ConfigContent?.ToString();
            string locationContent = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower() == "evidencelocation")?.ConfigContent?.ToString();
            string stageContent = configModel.ConfigDetail.FirstOrDefault(a => a.Code.ToLower() == "stagelocate").ConfigContent.ToString();
            //加载证据要素优选配置
            if(!string.IsNullOrWhiteSpace(optimizeContent))
                OptimizConfig= XmlUtility.DeserializeToObject<OptimizeConfig>(optimizeContent);
            //加载证据定位配置
            if(!string.IsNullOrWhiteSpace(locationContent))
                this.evidenceLocationConfig= XmlUtility.DeserializeToObject<EvidenceLocationConfig>(locationContent);
            //加载阶段定位配置
            if (!string.IsNullOrWhiteSpace(stageContent))
                this.stageConfig = XmlUtility.DeserializeToObject<StageConfig>(stageContent);
        }



        /// <summary>
        /// 证据要素优选开始
        /// </summary>
        /// <param name="incomingList">传入数据</param>
        /// <param name="resultList">优选结果数据</param>
        /// <param name="isSameStage">是否相同阶段</param>
        public void ElementOptimization(bool isSameStage=true)
        {
            XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = dataContext };
            //案件分析结果数据
            List<DataModel> dataModelAsisList = dataContext.DataLayerAns.AnalysisResultsDataModel.dataModelList;

            //传入证据详情数据
            List<DataModel> incomingEvidences = new List<DataModel>();
            //传入证据内容详情数据
            List<DataModel> incomingContents = new List<DataModel>();
            //上次优选证据详情数据
            List<DataModel> resultEvidences = new List<DataModel>();
            //优选结果证据内容详情数据
            List<DataModel> resultContents = new List<DataModel>();
            //传入数据定位配置
            Casetype casetype = evidenceLocationConfig.Casetypes.FirstOrDefault(x => x.code.ToLower() == dataContext.DataLayerAns.CaseType.ToLower());
            var booktype = casetype.Booktypes.FirstOrDefault(x => x.code.ToLower() == dataContext.DataLayerAns.SourceCode.ToLower());
            //案件要素xpath路径
            string caseElementPath = booktype.path;
            //优选结果阶段xpath路径
            string resultStagePath = string.Empty;

            List<DataModel> dataModelsOPList = new List<DataModel>();
            DAL_An_anjiancunchu anjiancunchudal = new DAL_An_anjiancunchu();
            var anjiancunchuList = anjiancunchudal.GetList(dataContext.DataLayerOpt.CaseId, "3");
            DataSoursModel dataSoursModel = new DataSoursModel();
            if(anjiancunchuList!=null && anjiancunchuList.Any())
            {
                dataSoursModel = GetDataSoursModel(ReadDataXML(anjiancunchuList[0].Wenjianid));
                List<DataModel> dataModels = dataSoursModel.dataModelList;
                //加载数据
                var sourceDatas = LoadData(isSameStage, caseElementPath, booktype,dataModels);
                incomingEvidences = sourceDatas.incomingEvidences;
                incomingContents = sourceDatas.incomingContents;
                resultEvidences = sourceDatas.resultEvidences;
                resultContents = sourceDatas.resultContents;
                resultStagePath = sourceDatas.stagePath;
                if (incomingContents != null && incomingContents.Any() && resultEvidences != null && resultEvidences.Any())
                {
                    foreach (DataModel incoming in incomingContents)
                    {
                        //优选结果相同证据内容详情数据
                        DataModel result = GetSameResultEvidence(incoming, incomingEvidences, resultEvidences, resultContents, resultStagePath, booktype);
                        //传入数据证据要素路径
                        string incomingElementPath = booktype.Element.path;
                        incomingElementPath = RemmovePathStage(incomingElementPath);
                        //优选结构证据要素路径
                        string resultElementPath = booktype.Element.path.Replace(booktype.path, resultStagePath);
                        resultElementPath = RemmovePathStage(resultElementPath);

                        List<DataModel> incomingElementList = SubordinateDataModelList(dataModelAsisList, incoming);
                        DataModel incomingElement = incomingElementList.FirstOrDefault(x => x.XmlPath == incomingElementPath);

                        List<DataModel> resultElementList = SubordinateDataModelList(dataModels, result);
                        DataModel resultElement = resultElementList.FirstOrDefault(x => x.XmlPath == resultElementPath);

                        //传入证据内容详情和优选证据内容详细中都有证据要素数据时执行案件要素优选
                        if (incomingElement != null && !string.IsNullOrWhiteSpace(incomingElement.ID) && resultElement!=null&& !string.IsNullOrWhiteSpace(resultElement.ID))
                        {
                            RestructureElment(resultElementList, resultElement.ID, "");
                            EvidenceElementOptimization(dataModels,incomingElement.ID, dataModelAsisList, OptimizConfig);
                            XmlDocument xmlDocumenttowff = xmlUtilCommon.DataModelByXml(dataModelAsisList, "");
                            foreach (DataModel moderomve in dataModelAsisList.Where(a => a.State == "2").ToList())
                            {
                                DataModel model = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(a => a.ID == moderomve.ID);
                                if (model != null)
                                {
                                    dataContext.DataLayerOpt.SourdatModleList.Remove(model);
                                }
                            }
                            dataModelAsisList = dataModelAsisList.Where(a => a.State != "2").ToList();
                            XmlDocument xmlDocumenttowcc = xmlUtilCommon.DataModelByXml(dataModelAsisList.Where(a => a.State != "2").ToList(), "");
                            AssignmentResult(dataModelAsisList);
                        }

                    }
                }
            }            
        }

        /// <summary>
        /// 证据要素优选
        /// </summary>
        /// <param name="resultList">优选结果数据</param>
        /// <param name="prentId"></param>
        /// <param name="incomingList">传入数据</param>
        /// <param name="optimizeConfig">优选配置</param>
        public void EvidenceElementOptimization(List<DataModel> resultList ,string prentId,List<DataModel> incomingList, OptimizeConfig optimizeConfig)
        {

            OptimizationData optimizationData = new OptimizationData() { dataContext = dataContext };
            optimizationData.IsStage = 1;
            List<DataModel> dataModelsAissNodeList = new List<DataModel>();
            if (dataContext.DataLayerAns.CaseCausesList != null && dataContext.DataLayerAns.CaseCausesList.Count > 0)
            {
                dataModelsAissNodeList = resultList.Where(a => a.ParentId == prentId && a.XmlPath.IndexOf(dataContext.DataLayerAns.CaseCausesList[0].CC_Name) < 0).ToList();
            }
            else
            {
                dataModelsAissNodeList = resultList.Where(a => a.ParentId == prentId).ToList();
            }
            if (dataModelsAissNodeList.Count > 0)
            {
                foreach (DataModel dataModelAsisNode in dataModelsAissNodeList)
                {
                    Xmllable xmllableCofigs = optimizeConfig.XmllableList.FirstOrDefault(a => a.Xmlpath == dataModelAsisNode.XmlPath);
                    if (xmllableCofigs != null && xmllableCofigs.Type == "b")
                    {
                        //单一数据源优选
                        #region 单一数据源
                        string parentid = "";
                        DataModel dataOpModel = new DataModel();
                        if (incomingList.FirstOrDefault(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2") == null)
                        {
                            string xmlpath = "";
                            for (int i = 0; i < xmllableCofigs.Xmlpath.Split('/').Length - 1; i++)
                            {
                                if (xmlpath == "")
                                {
                                    xmlpath = xmllableCofigs.Xmlpath.Split('/')[i];
                                }
                                else
                                {
                                    xmlpath = xmlpath + "/" + xmllableCofigs.Xmlpath.Split('/')[i];

                                }
                            }
                            if (incomingList.FirstOrDefault(a => a.XmlPath == xmlpath && a.State != "2") != null)
                            {
                                parentid = incomingList.FirstOrDefault(a => a.XmlPath == xmlpath).ID;
                                dataModelAsisNode.ParentId = parentid;
                                List<DataModel> dataModelListRestAiss = SubordinateDataModelList(resultList, dataModelAsisNode);
                                dataModelListRestAiss = JsonConvert.DeserializeObject<List<DataModel>>(JsonConvert.SerializeObject(dataModelListRestAiss));
                                RestructureElment(dataModelListRestAiss, dataModelAsisNode.ParentId, dataModelAsisNode.ParentId);
                                foreach (DataModel aissmodel in dataModelListRestAiss)
                                {
                                    aissmodel.State = "1";
                                    incomingList.Add(aissmodel);
                                }
                            }
                        }
                        else
                        {
                            dataOpModel = incomingList.FirstOrDefault(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2");
                            string modesours = dataOpModel.sourceData.sourceList.FirstOrDefault(a => a.IsCheck == "1").SourceCode;
                            string soursnameopid = optimizeConfig.Sourcedatadefine[0].SourcedataList.FirstOrDefault(a => a.Code.ToLower() == modesours.ToLower()).id.ToString();
                            string soursnameasisid = optimizeConfig.Sourcedatadefine[0].SourcedataList.FirstOrDefault(a => a.Code.ToLower() == dataModelAsisNode.sourceData.sourceList.FirstOrDefault(a => a.IsCheck == "1").SourceCode.ToLower()).id.ToString();
                            int opsum = ListByCount(xmllableCofigs.Priority.Split('>').ToList(), soursnameopid);
                            int assum = ListByCount(xmllableCofigs.Priority.Split('>').ToList(), soursnameasisid);
                            if (assum <= opsum)
                            {
                                if (incomingList.FirstOrDefault(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2") != null)
                                {
                                    List<DataModel> dataModelListOp = incomingList.Where(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2").ToList();
                                    foreach (DataModel dataop in dataModelListOp)
                                    {
                                        List<DataModel> dataModelListRest = SubordinateDataModelList(incomingList, dataop);
                                        parentid = dataop.ParentId;
                                        foreach (DataModel dataModelOP in dataModelListRest)
                                        {
                                            dataModelOP.State = "2";
                                        }
                                    }
                                }

                                List<DataModel> dataModels = dataModelsAissNodeList.Where(a => a.XmlPath == dataModelAsisNode.XmlPath)?.ToList();
                                if (dataModels != null)
                                {
                                    foreach (DataModel AsisNode in dataModels)
                                    {
                                        List<DataModel> dataModelListRestAiss = SubordinateDataModelList(resultList, AsisNode);
                                        dataModelListRestAiss.FirstOrDefault(a => a.ID == AsisNode.ID).ParentId = parentid;
                                        dataModelListRestAiss = JsonConvert.DeserializeObject<List<DataModel>>(JsonConvert.SerializeObject(dataModelListRestAiss));
                                        RestructureElment(dataModelListRestAiss, AsisNode.ParentId, AsisNode.ParentId);

                                        foreach (DataModel aissmodel in dataModelListRestAiss)
                                        {
                                            aissmodel.State = "1";
                                            incomingList.Add(aissmodel);
                                        }
                                    }
                                }



                            }
                            //if (assum == opsum)
                            //{
                            //    if (incomingList.FirstOrDefault(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2") != null)
                            //    {

                            //        DataModel modelOP = incomingList.FirstOrDefault(a => a.XmlPath == xmllableCofigs.Xmlpath && a.State != "2");
                            //        if (dataModelsAissNodeList.Count > 0)
                            //        {
                            //            modelOP.sourceData = dataModelAsisNode.sourceData;
                            //            modelOP.AttributesList = dataModelAsisNode.AttributesList;
                            //        }

                            //    }
                            //}
                        }

                        #endregion
                    }
                    else
                    {
                        #region 多数据源优选

                        dataContext.InteractiveShow.LogShow("当前分析的路径" + dataModelAsisNode.XmlPath);
                        dataContext.InteractiveShow.LogShow("当前分析的id" + dataModelAsisNode.ID);
                        List<DataModel> dataModelListAsis = new List<DataModel>();//分析下级循环合集
                        List<DataModel> dataModelListOP = new List<DataModel>();//优选下级循环合集
                        dataModelListAsis = resultList;
                        dataModelListOP = incomingList;
                        Xmllable xmllableCofig = optimizeConfig.XmllableList.FirstOrDefault(a => a.Xmlpath == dataModelAsisNode.XmlPath);
                        if (xmllableCofig != null)
                        {
                            bool determine = true;
                            if (xmllableCofig.ConditionList.Count > 0)
                            {
                                try
                                {
                                    determine = ConditionDetermine(xmllableCofig.ConditionList);
                                }
                                catch (System.Exception ef)
                                {
                                    dataContext.InteractiveShow.LogShow("当前数据项条件解析错误，配置信息：" + JsonConvert.SerializeObject(ef.ToString()));
                                    dataContext.InteractiveShow.LogShow("当前数据项条件解析错误，错误信息：" + ef.ToString());
                                }
                            }
                            if (determine)
                            {
                                DataModel dataModelOpSging = new DataModel();
                                if (xmllableCofig.Type == "a")
                                {
                                    foreach (var element in xmllableCofig.SignnodeList.NodeList)
                                    {
                                        if (dataModelAsisNode.AttributesList.FirstOrDefault(a => a.Name == element.Code) != null)
                                        {

                                            string elementvalue = dataModelAsisNode.AttributesList.FirstOrDefault(a => a.Name == element.Code).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                                            dataContext.InteractiveShow.LogShow("进入标识优选值：" + elementvalue);
                                            dataModelOpSging = dataModelListOP.FirstOrDefault(a => a.XmlPath == xmllableCofig.Xmlpath && a.AttributesList.FirstOrDefault(b => b.Name == element.Code &&
                                            b.sourceList.FirstOrDefault(s => s.IsCheck == "1" && s.SaveValue == elementvalue) != null) != null);
                                            if (dataModelOpSging != null)
                                            {
                                                dataContext.InteractiveShow.LogShow("进入标识查询成功!");
                                                dataModelListOP = SubordinateDataModelList(incomingList, dataModelOpSging);
                                                List<DataModel> parentNodeModel = ParendNodeDataModelList(incomingList, dataModelOpSging);
                                                dataModelListOP.AddRange(parentNodeModel);

                                            }

                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    dataModelOpSging = dataModelListOP.FirstOrDefault(a => a.XmlPath == xmllableCofig.Xmlpath && a.State != "2");
                                }
                                optimizationData.OptimizationDataRun(dataModelAsisNode, dataModelOpSging, xmllableCofig, optimizeConfig, dataModelListOP, resultList);
                            }
                            EvidenceElementOptimization(resultList, dataModelAsisNode.ID, dataModelListOP, optimizeConfig);
                            foreach (DataModel opModel in dataModelListOP)
                            {
                                if (incomingList.FirstOrDefault(a => a.ID == opModel.ID && a.State == opModel.State) != null)
                                {

                                    DataModel model = incomingList.FirstOrDefault(a => a.ID == opModel.ID);
                                    model = opModel;

                                }
                                else
                                {
                                    incomingList.Add(opModel);
                                }
                            }
                        }
                        else
                        {

                            EvidenceElementOptimization(resultList, dataModelAsisNode.ID, incomingList, optimizeConfig);
                        }


                        #endregion
                    }
                }
            }


        }


        /// <summary>
        /// 将优选结果赋值于优选结果中
        /// </summary>
        public void AssignmentResult(List<DataModel> resultList)
        {
            foreach (DataModel dataModelStage in resultList)
            {
                DataModel resultModel = dataContext.DataLayerOpt.SourdatModleList.FirstOrDefault(a => a.ID == dataModelStage.ID);
                if (resultModel != null)
                {
                    resultModel.AttributesList = dataModelStage.AttributesList;
                    //结果为本次优选结果
                    resultModel.sourceData = dataModelStage.sourceData;
                    resultModel.State = dataModelStage.State;
                }
                else
                {
                    if (!string.IsNullOrEmpty(dataModelStage.ParentId))
                    {
                        dataContext.DataLayerOpt.SourdatModleList.Add(dataModelStage);
                    }
                }
            }

        }

        /// <summary>
        /// 去除xpath路径中的阶段数据
        /// </summary>
        private string RemmovePathStage(string path)
        {
            Regex r = new Regex(@"\[[^,，。;；/]*?\]");
            MatchCollection mc = r.Matches(path);
            for (int i = 0; i < mc.Count; i++)
            {
                path = path.Replace(mc[i].Value, "");
            }

            return path;
        }

        private (List<DataModel> incomingEvidences, List<DataModel> incomingContents, List<DataModel> resultEvidences,List<DataModel>resultContents,string stagePath) LoadData(bool isSameStage,string caseElementPath, Booktype booktype,List<DataModel> dataModels)
        {
            //传入证据详情数据
            List<DataModel> incomingEvidenceList = new List<DataModel>();
            //传入证据内容详情数据
            List<DataModel> incomingContentList = new List<DataModel>();
            //上次优选证据详情数据
            List<DataModel> resultEvidenceList = new List<DataModel>();
            //上次优选证据内容详情数据
            List<DataModel> resultContentList = new List<DataModel>();
            //上阶段路径
            string resultStagePath = string.Empty;
            //案件分析结果数据
            List<DataModel> dataModelAsisList = dataContext.DataLayerAns.AnalysisResultsDataModel.dataModelList;
            //FilterCaseElment(dataModelAsisList);
            //上次案件优选结果数据
            List<DataModel> dataModelsOPList = new List<DataModel>();
            if (dataModels.Any())
            {
                if(isSameStage)
                {
                    resultEvidenceList = XmlUtility.ConditionDataModelList(dataModels, "", booktype.Evidence.path);
                    resultStagePath = booktype.path;
                }
                else
                {
                    //上阶段配置数据
                    StageModel resultStage = ObtainStage(stageConfig, dataContext.DataLayerAns.StageProcessAnalysisModel.id);
                    if (resultStage!=null)
                    {
                        string resultEvidencePath = booktype.Evidence.path.Replace(caseElementPath, resultStage.path);
                        resultEvidenceList = XmlUtility.ConditionDataModelList(dataModels, "", resultEvidencePath);
                        string resultContentPath = booktype.Content.path.Replace(caseElementPath, resultStage.path);
                        resultContentList= XmlUtility.ConditionDataModelList(dataModels, "", resultContentPath);
                        resultStagePath = resultStage.path;
                    }
                }

            }
            incomingEvidenceList= XmlUtility.ConditionDataModelList(dataModelAsisList, "", booktype.Evidence.path);
            incomingContentList = XmlUtility.ConditionDataModelList(dataModelAsisList, "", booktype.Content.path);
            return (incomingEvidenceList, incomingContentList, resultEvidenceList,resultContentList, resultStagePath);
        }

        /// <summary>
        /// 获取上阶段配置数据
        /// </summary>
        public StageModel ObtainStage(StageConfig stageModelConfig, int id)
        {
            id = id - 1;
            if (id >= 0)
            {
                StageModel stageModel = stageModelConfig.stageModelList.FirstOrDefault(a => a.id == id.ToString());
                if (stageModel != null)
                {
                    DataModel dataModel = XmlUtility.ConditionFirstOrDefaultDataModel(dataContext.DataLayerOpt.SourdatModleList, "", stageModel.path);
                    if (dataModel != null)
                    {
                        return stageModel;
                    }
                    else
                    {
                        return ObtainStage(stageModelConfig, id);
                    }
                }
                else
                {
                    return ObtainStage(stageModelConfig, id);
                }
            }
            return null;
        }

        /// <summary>
        /// 获取优选结果相同证据内容详情数据
        /// </summary>
        /// <param name="incomingContent">传入证据内容详情数据</param>
        /// <param name="incomingEvidences">传入证据详情数据</param>
        /// <param name="resultEvidences">优选结果证据详情集合</param>
        /// <param name="resultContents">优选结果证据详情集合</param>
        /// <param name="resultStagePath">优选结果阶段路径</param>
        /// <returns></returns>
        private DataModel GetSameResultEvidence(DataModel incomingContent,List<DataModel> incomingEvidences , List<DataModel> resultEvidences,List<DataModel> resultContents,string resultStagePath,Booktype booktype)
        {
            DataModel sameData = null;

            XmlUtilCommon xmlUtilCommon = new XmlUtilCommon() { dataContext = dataContext };
            //传入阶段路径
            string incomingStagePath = booktype.path;
            //证据详情判断条件
            List<EvidenceCondition> evidenceConditions = booktype.Evidence.Conditions;
            //证据内容详情判断条件
            List<ContentCondition> contentConditions = booktype.Content.Conditions;
            
            var incomingEvidencePath = booktype.Evidence.path;
            DataModel incomingEvidence = new DataModel();
            Regex r = new Regex(@"\[[^,，。;；/]*?\]");
            incomingEvidencePath = RemmovePathStage(incomingEvidencePath);

            var resultEvidencePath = booktype.Evidence.path.Replace(booktype.path, resultStagePath);
            resultEvidencePath= RemmovePathStage(resultEvidencePath);
            List <DataModel> incomingParents = xmlUtilCommon.SubParentDateModelNoDM(incomingEvidences, incomingContent);
            incomingEvidence = incomingParents.FirstOrDefault(x => x.XmlPath == incomingEvidencePath);
            foreach (DataModel content in resultContents)
            {
                bool isSame = true;
                if (booktype.Content.Conditions!=null && booktype.Content.Conditions.Any())
                {
                    foreach (ContentCondition ec in booktype.Content.Conditions)
                    {
                        if (content.AttributesList.FirstOrDefault(x=>x.Name==ec.name)!=null)
                        {
                            string resultValue = content.AttributesList.FirstOrDefault(a => a.Name == ec.name).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                            string incomingValue= incomingContent.AttributesList.FirstOrDefault(a => a.Name == ec.name).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                            if (resultValue != incomingValue)
                                isSame = false;
                        }
                    }
                }
                if (isSame)
                {
                    List<DataModel> resultParents= xmlUtilCommon.SubParentDateModelNoDM(incomingEvidences, content);
                    DataModel resultEvidence = new DataModel();
                    resultEvidence= resultParents.FirstOrDefault(x => x.XmlPath == resultEvidencePath);
                    foreach (EvidenceCondition condition in booktype.Evidence.Conditions)
                    {
                        if (content.AttributesList.FirstOrDefault(x => x.Name == condition.name) != null)
                        {
                            string resultValue = content.AttributesList.FirstOrDefault(a => a.Name == condition.name).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                            string incomingValue = incomingContent.AttributesList.FirstOrDefault(a => a.Name == condition.name).sourceList.FirstOrDefault(a => a.IsCheck == "1").SaveValue;
                            if (resultValue != incomingValue)
                                isSame = false;
                        }
                    }
                }
                if(isSame)
                {
                    sameData = content;
                    continue;
                }
            }
            return sameData;
        }
    }
}
